from flask import url_for


def to_public(path: str) -> str:
    if not path:
        return ''
    if path.startswith('http://') or path.startswith('https://'):
        return path
    # 如果数据库里存的是 'uploads/products/xxx.jpg' → 截掉前缀给 /uploads 路由用
    if path.startswith('uploads/'):
        rel = path.split('uploads/', 1)[1]  # 'products/xxx.jpg'
        return url_for('uploaded_file', filename=rel)
    # 如果你有时存 'products/xxx.jpg'（不带 uploads 前缀）
    return url_for('uploaded_file', filename=path)
